package com.ill.legou.item.controller;

import com.ill.legou.item.po.Brand;
import com.ill.legou.item.po.Category;
import com.ill.legou.item.service.IBrandService;
import com.lxs.legou.core.controller.BaseController;
import com.lxs.legou.core.po.BaseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping(value="/brand")
@CrossOrigin
public class BrandController extends BaseController<IBrandService, Brand> {


    /*
    * 这个是用于当将category信息村放到brand里边去
    * */
    @Override
    public void afterEdit(Brand entity) {
        List<Category> categories =service.selectCategoryByBrandId(entity.getId());
        Long[] ids =new Long[categories.size()];
        for (int i = 0; i < categories.size(); i++) {
            ids[i] =categories.get(i).getId();
        }

        entity.setCategoryIds(ids);
        //最后结果是需要把entity的ids赋值进去
    }
}
